<?php ob_start(); session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Góp ý - Phản hồi</title>
<link href="../Twitter_Bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="../CSS/css_admin.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="../CSS/validationEngine.jquery.css"/>
<link rel="stylesheet" type="text/css" href="../Twitter_Bootstrap/css/datepicker.css"/>

<script type="text/javascript" src="../Twitter_Bootstrap/js/jquery.js"></script>
<script type="text/javascript" src="../Twitter_Bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../Scripts/jquery.validationEngine.js"></script>
<script type="text/javascript" src="../Scripts/jquery.validationEngine-vi.js"></script>
<script type="text/javascript" src="../Twitter_Bootstrap/js/bootstrap-datepicker.js"></script>




<style type="text/css">
<!--
#tbResult td,#tbResult th
{
	text-align:center;
}
-->
</style>
</head>

<body>
<div class="container" id="Container">
<!--Menu top -->
  <div id="menu">
  	<?php
		include("../Connections/connect_admin.php");
		include("MainMenu.php");
		$page=1;
		$recordPerPage=10;
		if(isset($_GET["page"]))
			{
				$page=intval($_GET["page"]);
			}
		$index=($page-1)*$recordPerPage;
		$query="SELECT * FROM feedback f ORDER BY f.CreatedDate desc ";
		$fromdate='';
		$todate='';
		$type=0;
		if(isset($_GET['fromdate'])&&isset($_GET['todate'])&&isset($_GET['type']))
		{
			$type=intval($_GET['type']);
			$arr1=explode('-',$_GET['fromdate']);
			$fromdate=$arr1[2].'-'.$arr1[1].'-'.$arr1[0];
			$arr2=explode('-',$_GET['todate']);
			$todate=$arr2[2].'-'.$arr2[1].'-'.$arr2[0];
			
			$query="SELECT * FROM feedback f WHERE (f.FeedbackType=$type OR $type=0 ) AND (f.CreatedDate BETWEEN '$fromdate' AND '$todate') ORDER BY f.CreatedDate desc ";
		}
	
		$sql=$query." Limit $index,$recordPerPage";
  		$result=mysql_query($sql);
	?>
    </div>
  </div>
  <div id="divContain">
  <!--Content -->
   <div class="divTitle"><span class="titlePage" >Góp ý - Phản hồi</span></div>
  	<div style="padding-top:30px" >
     <form action="" method="get" id="formSearch" class="form-horizontal">
 		
        <input type="text" id="txtStartDate" placeholder="Từ ngày..." data-date-format="dd-mm-yyyy" class="validate[funcCall[checkRangeDate],required]" name="fromdate" <?php if(isset($_GET['fromdate'])) echo "value='".$_GET['fromdate']."'"; ?> >
        <input type="text" id="txtEndDate" placeholder="Đến ngày..." data-date-format="dd-mm-yyyy" class="validate[funcCall[checkRangeDate],required]" name="todate" <?php if(isset($_GET['todate'])) echo "value='".$_GET['todate']."'"; ?> >
        <select id="cbxFeedbackType" name="type">
        	<option value="0" <?php if($type==0) echo "selected='selected'"?>>---Loại góp ý---</option>
            <option value="1" <?php if($type==1) echo "selected='selected'"?>>Báo lỗi</option>
            <option value="2" <?php if($type==2) echo "selected='selected'"?>>Góp ý nội dung</option>
            <option value="3" <?php if($type==3) echo "selected='selected'"?>>Yêu cầu chức năng</option>
            <option value="4" <?php if($type==4) echo "selected='selected'"?>>Khác</option>
        </select>
        <button class="btn" type="submit" id="btnSearch"><i class=" icon-search"></i> Tìm kiếm</button> 
    </form>
    <script>
	$(function() {
			$( "#txtStartDate" ).datepicker();			
			$( "#txtEndDate" ).datepicker();
			$('#formSearch').validationEngine();
	
			
				}); 
	function checkRangeDate(field, rules, i, options){
		//-----------------------------------Kiểm tra khoảng ngày------------------------------------
				if($( "#txtStartDate" ).val()!=''||$( "#txtEndDate" ).val()!='')
				{
				var arrStartDate=$('#txtStartDate').val().split("-");
				var startDate=new Date(arrStartDate[2],arrStartDate[1],arrStartDate[0]);
				var arrEndDate=$('#txtEndDate').val().split("-");
				var endDate=new Date(arrEndDate[2],arrEndDate[1],arrEndDate[0]);
						if (startDate>endDate) {
							// this allows to use i18 for the error msgs
							 
							 return options.allrules.validateRangeDate.alertText;
						}
						
				}
					}
	</script>
    <table class="table table-bordered table-striped  " id="tbResult" width="100%" border="0" cellspacing="0" cellpadding="0" >
  <tr>
  	<th scope="col" class="hide">Mã</th>
    <th scope="col">Ngày gởi</th>
    <th scope="col">Loại góp ý</th>
    <th scope="col">Email</th>
    <th scope="col">Link</th>
    <th scope="col">Nội dung góp ý</th>
    <th scope="col"></th>
  </tr>
  <?php
  	while( $row=mysql_fetch_assoc($result))
	{
  ?>
  <tr>
    <td class="hide"><?php echo $row['FeedbackID']; ?></td>
    <td><?php $sqldate=strtotime($row["CreatedDate"]); $date=date('d/m/y',$sqldate); echo $date; ?></td>
    <td>
	<?php switch($row['FeedbackType'])
		{
				case 1:
				echo 'Báo lỗi';
				break;
				case 2:
				echo 'Góp ý nội dung';
				break;
				case 3:
				echo 'Yêu cầu chức năng';
				break;
				case 4:
				echo 'Khác';
				break;
		}
	?>
    </td>
    <td><?php echo $row['Email']; ?></td>
    <td><?php echo $row['Link']; ?></td>
    <td><?php echo $row['Content']; ?></td>
    <td><a href="#" title="Xóa" class="delete"><img src="../Images/Icons/delete.png" alt="delete" /></a></td>

  </tr>
  <?php
	}
  ?>
</table>
	<script type="text/javascript">
	$(document).ready(function(){
							   
							   $('.delete').live('click',function(){
									if(confirm('Bạn thật sự muốn xóa?'))
									{
									var $temp=$(this);
									var fid=$(this).parent().parent().children().eq(0).text();
									$.ajax({
										   url:"process/Feedback_process.php",
										   data:{id:fid},
										   type:"get",
										   dataType:"json",
										   success: function(res)
										   {
											   if(res.ok)
											   {
												   $temp.parent().parent().remove();
											   }
											   alert(res.msg);
										   }
										   });	
									}
								});
	});
	</script>

	<div class="pagination pull-right">
   		 <?php require("process/funcPaging.php");
			
			if(isset($_GET["type"]))
			{
				$type=intval($_GET['type']);				
				$fromdate=$_GET['fromdate'];				
				$todate=$_GET['todate'];
				$link="Feedback.php?type=".$type."&fromdate=".$fromdate."&todate=".$todate."&";
			}
			else
			{	
				$link="Feedback.php?";
			}
			$resAll=mysql_query($query);
			$total=mysql_num_rows($resAll);
			
			Paging($total,$page,5,$recordPerPage,$link);
 		?>
    </div>
	</div>
  <!--footer -->
  </div>
  <div id="footer">
     <?php
     	include("Footer.php");
	 ?>
  </div>
</div>
</body>
</html>
